//
//  ViewController.m
//  往沙盒中存数据和取数据Demo
//
//  Created by 向祖华 on 16/3/30.
//  Copyright © 2016年 向祖华. All rights reserved.
//

#import "ViewController.h"
#import "SandBoxDemo.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
#pragma mark - 沙盒中Documents文件夹的数据管理
    NSString * string =@"做一个程序员";
    //存数据
    BOOL result = [SandBoxDemo storeDataWithString:string key:@"001"];
    NSLog(@"存数数据是否成功 ：%d",result);
    //取数据
    NSString * str =[SandBoxDemo takeDataWithKey:@"001"];
    NSLog(@"%@",str);
    //删除数据
    BOOL deletResult = [SandBoxDemo deletDataWithKey:@"001"];
    NSLog(@"删除数据是否成功 ：%d",deletResult);
    
#pragma mark - 沙盒中tmp文件夹的数据管理
    NSArray * arr = @[@"女程序员",@"男程序员"];
    //存数据
    BOOL result1 = [SandBoxDemo tempStoreDataWithArray:arr Key:@"002"];
    NSLog(@"存储数据是否成功%d",result1);
    //取数据
    NSArray*array =[SandBoxDemo tempTakeDataWithKey:@"002"];
    NSLog(@"%@",array);
    //删除数据
    BOOL deletResult1 = [SandBoxDemo tempDeletDataWithKey:@"002"];
    NSLog(@"删除数据是否成功%d",deletResult1);
    
#pragma mark -- 沙盒中caches文件夹的数据管理
    UIImage * image =[UIImage imageNamed:@"1"];
    //存数据
    BOOL result2 = [SandBoxDemo cachesStoreDataWithImage:image key:@"003"];
    NSLog(@"存数数据是否成功 ：%d",result2);
    //取数据
    UIImage * img = [SandBoxDemo cachesTakeDataWithKey:@"003"];
    NSLog(@"%@",img);
    //删除数据
    BOOL deletResulet = [SandBoxDemo cachesDeleteDataWithKey:@"003"];
    NSLog(@"删除数据是否成功：%d",deletResulet);
#pragma mark -- 管理文件
    //在temp文件夹中创建文件夹
    BOOL result3 =[SandBoxDemo creatFileWithKey:@"004"];
    NSLog(@"创建文件夹成功：%d",result3);
    //往文件夹中写入数据
    BOOL writResulte3 = [SandBoxDemo writDataWithString:@"这个真牛逼" key:@"004"];
    NSLog(@"写入数据成功：%d",writResulte3);
    //将文件夹移到caches文件夹中
    BOOL moveResult =[SandBoxDemo moveFileWithKey:@"004"];
    NSLog(@"移动文件夹成功：%d",moveResult);
    //将文件夹删掉
    BOOL deleteResult = [SandBoxDemo deleteFileWithKey:@"004"];
    NSLog(@"删除文件夹成功：%d",deleteResult);
    //将文件夹复制到Documents文件夹
    BOOL copyResult = [SandBoxDemo copyFileWithKey:@"004"];
    NSLog(@"复制文件夹成功：%d",copyResult);
    
#pragma mark -- 归档与反归档
    //创建需要归档的对象
    Person * p1 = [[Person alloc] init];
    p1.name = @"齐天大圣";
    p1.age = 500;
    p1.image = [UIImage imageNamed:@"1"];
    
    //归档
    BOOL result4 = [SandBoxDemo encodeWithData:p1 key:@"005"];
    NSLog(@"归档数据成功：%d",result4);
    //反归档
    Person * p2 = [SandBoxDemo decodeWithKey:@"005"];
    NSLog(@"反归档的数据为：%@",p2);
    
}

@end
